package com.wqnmdb.im.domain.resp;

import com.wqnmdb.im.domain.contants.ConstantEnum;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.HashMap;
import java.util.Map;


public class RespUtils {

    private static final Map EMPTY = new HashMap<>();

    /**
     * 返回成功~
     */
    public static ResponseEntity<R> success(Object result){
        return new ResponseEntity<>(new R(result), HttpStatus.OK);
    }

    public static ResponseEntity<R> successMsg(String msg){
        return new ResponseEntity<>(new R(msg, EMPTY), HttpStatus.OK);
    }

    /**
     * 返回失败
     */
    public static ResponseEntity<R> fail(String msg){
        return new ResponseEntity<>(new R(ConstantEnum.FAIL.getCode() , msg, EMPTY), HttpStatus.OK);
    }

    public static ResponseEntity<R> fail(int code, String msg) {
        return new ResponseEntity<>(new R(code, msg, EMPTY), HttpStatus.OK);
    }

    /**
     * 返回异常
     */
    public static ResponseEntity<R> error(int code, String msg) {
        return new ResponseEntity<>(new R(code, msg, EMPTY), HttpStatus.OK);
    }


    /**
     * 适配https的协议转换~
     */
    public static ResponseEntity<R> convert(R r){
        return new ResponseEntity<>(r, HttpStatus.OK);
    }

}
